// shows the header with the display name(the user is logged in)
function setLoggedin(displayName){
	var displayname = document.getElementById("displayname");
	displayname.innerHTML = "Hi " + displayName;
	removeLoginForm();
}

//shows the login form
function setUnLogged(isError){
	if(isError && document.getElementById("errorloginmessagme") == null){
		errorMessage = document.createElement('div');
		errorMessage.setAttribute('id', 'errorloginmessagme');
		errorMessage.setAttribute('class', 'errormessagme');
		errorMessage.innerHTML = "login failed";
		document.getElementById("container").appendChild(errorMessage);
	}
	document.getElementById("userName").style.visibility="visible";
	document.getElementById("password").style.visibility="visible";
	document.getElementById("submitLogin").style.visibility="visible";
}

function removeLoginForm(){
	document.getElementById("userName").style.visibility="hidden";
	document.getElementById("password").style.visibility="hidden";
	document.getElementById("submitLogin").style.visibility="hidden";
	document.getElementById("headertextfooter").style.visibility="hidden";
	}

function login(){
	var params = new Object();
	params.userName = document.getElementById("userName").value;
	params.password = document.getElementById("password").value;
	userLogin(params);
}


//register 


function register(){
	var params = new Object();
	params.userName = document.getElementById("userName").value;
	params.displayName = document.getElementById("displayName").value;
	params.password = document.getElementById("password").value;
	newUser(params);

}


function checkPasswords(){
	var input = document.getElementById('secondPassword');
	if (input.value != document.getElementById('password').value) {
        input.setCustomValidity('The two passwords must match.');
    } else {
        // input is valid -- reset the error message
        input.setCustomValidity('');
}
}

function registrationError(errorMessage){
	if(document.getElementById("errorregistermessagme") == undefined){
	errorMessage = document.createElement('div');
	errorMessage.setAttribute('id', 'errorregistermessagme');
	errorMessage.setAttribute('class', 'errormessagme');
	errorMessage.innerHTML = "registeration failed"; 
	document.getElementById("register").appendChild(errorMessage);
}
}